{include file="Public/header" /}
<div class="row">
    <div class="col-md-6" style="width: 100%;">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title">标签添加</h3>
            </div>
            <!--<form role="form" action="/admin/tag_add" role="form" menctype="multipart/form-data" method="post">-->
                <!--<form action="">-->
                <div class="box-body">
                    <div class="form-group">
                        <label >标签名</label>
                        <input type="name" class="form-control" name="name" id="name" placeholder="请输入标签名...">
                    </div>
                </div>
                <div class="box-footer">
                    <button type="submit" id="submit" class="btn btn-primary">Submit</button>
                </div>
            <!--</form>-->
        </div>
    </div>
</div>
<script src="/static/js/jquery-1.8.0.min.js" type="text/javascript" charset="utf-8" ></script>

<script>
    //一般直接写在一个js文件中
//    layui.use(['layer', 'form'], function(){
//        var layer = layui.layer
//            ,form = layui.form;
//
//        layer.msg('Hello World');
//    });
$(function () {
    $('#submit').click(function() {
        $(this).html('正在操作...');
        $(this).addClass('disabled');
        var name= $('input[name=name]').val();
        if(name==''){
            layui.use(['layer', 'form'], function(){
                var layer = layui.layer,form = layui.form;
                layer.msg('标签名称不能为空');
            });
            setTimeout(function(){window.location.href="/admin/tag_add";}, 3000);
        }
        $.ajax({
            url:'/admin/tag_add_ajax',
            type:'post',
            data:{name:name},
            dataType:"json",
            success:function(data){
                if(data.code == 1){
                    layui.use(['layer', 'form'], function(){
                        var layer = layui.layer,form = layui.form;
                        layer.msg(data.msg);
                    });
                    setTimeout(function(){window.location.href="/admin/tag_list";}, 3000);
                }else{
                    layui.use(['layer', 'form'], function(){
                        var layer = layui.layer,form = layui.form;
                        layer.msg(data.msg);
                    });
                    setTimeout(function(){window.location.href="/admin/tag_list";}, 3000);
                }
            }
        });
        return false;
    });
})
//    $(function(){
//
//    })
</script>
{include file="Public/footer" /}